﻿using UnityEngine;
using System.Collections;

public class CameraTracksFish : MonoBehaviour {

	Transform mainFish;
	float offSetX = 0.05f;
	float offSetY = 0.05f;

	// Use this for initialization
	void Start () {
		GameObject mainFish_go = GameObject.FindGameObjectWithTag ("MainFish");
		mainFish = mainFish_go.transform;
	}
	
	// Update is called once per frame
	void Update () {
		Vector3 pos = transform.position;
		if (mainFish.position.x <= -0.320296f) {
			if(transform.position.x - offSetX > 0.08095443f){
			pos.x -= offSetX;
			transform.position = pos;
			}
		}

		if (mainFish.position.x >= 2.320966f) {
			if(transform.position.x + offSetX < 2.424979f){
			pos.x += offSetX;
			transform.position = pos;
			}
		}

		if (mainFish.position.y <= -1.120424f) {
			if(transform.position.y - offSetY > -1.873409f){
				pos.y -= offSetY;
				transform.position = pos;
			}
		}

		if (mainFish.position.y >= -1.120424f && mainFish.position.y < 0.2510008f) {
				if(transform.position.y + offSetY < -0.2697675f){
				pos.y += offSetY;
				transform.position = pos;
				}
				else if(transform.position.y - offSetY > -0.2697675f){
					pos.y -= offSetY;
					transform.position = pos;
				}
		}
		//1.249444f
		if (mainFish.position.y >= 0.2756714f) {
			if(transform.position.y + offSetY < 1.249444f){
				pos.y += offSetY  ;
				transform.position = pos;
			}
		}
			

	}
}
